
# 运算重载2
# 创建一个自己的容器类，MyList, 实现各种运算符的重载
class MyList:
    def __init__(self, iterable=None):
        pass
    def __str__(self):
        return '| |'
    def __contains__(self, item):
        '用于 in 运算符 '
        print('item=', item)
        return True
    def __getitem__(self, item):
        print('item:', item)
        return 'xxxxx'
    def __mul__(self, other):
        print('other:', other)
        return 999999
a_list = MyList()
print(a_list)  #  | |
print(100 in a_list)  # True / False
print(100 not in a_list)  # False
print(a_list[888])  # 调用a_list.__getitem__(888)

list2 = a_list * 2  # a_list.__mul__(2)

